#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define ep emplace
#define rep(i, x, y) for(int i = (x); i <= (y); i++) 
#define per(i, x, y) for(int i = (x); i >= (y); i--)

using namespace std;

using ll = long long;
using db = double;
using pii = pair < int , int >;
using vec = vector < int >;
using veg = vector < pii >;

int read() {
	int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch == '-', ch = getchar(); 
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = getchar(); return f ? -x : x;
}

const int N = 1e5 + 10;

ll f[N];
int W, n, b[N], cnt;

namespace T {
	ll tr[N];
	void add(int x, ll v) { for(; x <= cnt; x += x & -x) tr[x] = max(tr[x], v); }
	void clr(int x) { for(; x <= cnt; x += x & -x) tr[x] = 0; }
	ll query(int x) { ll res = 0; for(; x; x -= x & -x) res = max(res, tr[x]); return res; }
}

struct node {
	int id, a, b, c, v; 
} p[N], q[N];

void solve(int l, int r) { // md, bu hui yi ge log.
	if(l == r) return; int mid = (l + r) >> 1;
	sort(p + l, p + r + 1, [](node x, node y) { return x.a ^ y.a ? x.a < y.a : x.b ^ y.b ? x.b < y.b : x.c < y.c; });
	solve(l, mid); int p1 = l, p2 = mid + 1;
	sort(p + l, p + mid + 1, [](node x, node y) { return x.b ^ y.b ? x.b < y.b : x.c ^ y.c ? x.c < y.c : x.a < y.a; });
	sort(p + mid + 1, p + r + 1, [](node x, node y) { return x.b ^ y.b ? x.b < y.b : x.c ^ y.c ? x.c < y.c : x.a < y.a; });
	while(p1 <= mid && p2 <= r) {
		if(p[p1].b <= p[p2].b) T :: add(p[p1].c, f[p[p1].id]), /*cerr << p[p1].c << endl, */p1++;
		else f[p[p2].id] = max(f[p[p2].id], T :: query(p[p2].c) + p[p2].v), /*cerr << "!" << p[p2].c << endl, */p2++;
	}
	while(p2 <= r) /*cerr << "!" << p[p2].c << endl, */f[p[p2].id] = max(f[p[p2].id], T :: query(p[p2].c) + p[p2].v), p2++;
	//rep(k, p1, mid) q[++cnt] = p[k];
	p1--; while(p1 >= l) T :: clr(p[p1].c), p1--;
	//cerr << endl;
	solve(mid + 1, r);
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in", "r", stdin);
#endif
	W = in, n = in;
	rep(i, 1, n) {
		int t = in, pos = in, v = in;
		p[i].id = i; p[i].a = t; p[i].b = t * 2 - pos; p[i].c = b[++cnt] = t * 2 + pos; p[i].v = v; f[i] = v;
	}
	sort(b + 1, b + cnt + 1); cnt = unique(b + 1, b + cnt + 1) - b - 1; 
	rep(i, 1, n) p[i].c = lower_bound(b + 1, b + cnt + 1, p[i].c) - b, assert(p[i].c);
	sort(p + 1, p + n + 1, [](node x, node y) { return x.a ^ y.a ? x.a < y.a : x.b ^ y.b ? x.b < y.b : x.c < y.c; });
	/*
	  rep(i, 1, n) {
		rep(j, 1, i - 1)
			if(p[i].a >= p[j].a && p[i].b >= p[j].b && p[i].c >= p[j].c)
				f[p[i].id] = max(f[p[i].id], f[p[j].id] + p[i].v);
				}
	*/
	solve(1, n);
	ll ans = 0;	rep(i, 1, n) ans = max(ans, f[i]); printf("%lld\n", ans);
	return 0;
}
